﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using SimpleLogicAnalyzer;

namespace UnitTests
{
    [TestFixture]
    public class TestVirtualCommunication
    {
        [Test]
        public void TestWakeup()
        {
            VirtualSlaCommunication virtualSlaCommunication = new VirtualSlaCommunication(115200);

            virtualSlaCommunication.Write("I");

            const string expectedResponse = "SLA_ANTONIAK_V1";
            StringBuilder receivedResponse = new StringBuilder(expectedResponse.Length);
            for (int index = 0; index < expectedResponse.Length; index++)
            {
                receivedResponse.Append((char)virtualSlaCommunication.ReadChar());
            }
            Assert.That(receivedResponse.ToString(), Is.EqualTo(expectedResponse));
        }

        [Test]
        public void TestReset()
        {
            VirtualSlaCommunication virtualSlaCommunication = new VirtualSlaCommunication(115200);

            virtualSlaCommunication.Write("Q");

            Assert.That(virtualSlaCommunication.BytesToRead, Is.EqualTo(0));
        }

        [Test]
        public void TestAcquireData()
        {
            VirtualSlaCommunication virtualSlaCommunication = new VirtualSlaCommunication(115200);

            byte[] command = new byte[12];

            // Create the command
            //command.

            virtualSlaCommunication.Write(command, 0, command.Length);

            Assert.That(virtualSlaCommunication.BytesToRead, Is.EqualTo(0));
        }

        [Test]
        public void TestTake()
        {
            byte[] array = new byte[] { 0, 1, 2, 3, 4, 5 };

            List<byte> list = new List<byte>(array.Take(3));

            Assert.That(list.Count, Is.EqualTo(3), "Number of items in the array");
            for(int i = 0; i < list.Count; i++)
            {
                Assert.That(list[i], Is.EqualTo(i), string.Format("Value of the item in the list at position {0}", i));
            }
        }
    }
}
